package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import tech.aistar.dto.Result;
import tech.aistar.entity.Collect;
import tech.aistar.service.ICollectService;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping(value = "/Collect")
public class CollectAction  {
    @Autowired
    private ICollectService collectService;
    @PostMapping("/col")
    public Result collect(HttpServletRequest request, HttpSession session) {

        String diff = request.getParameter("diff");
        String stem = request.getParameter("stem");
        String language = request.getParameter("lan");
        Long  id =Long.valueOf( request.getParameter("id"));
        //System.out.println(id);
        Collect collect = new Collect();
        collect.setLanguageType(language);
        collect.setColDiff(diff);
        collect.setColStem(stem);
        collect.setColId(id);
        System.out.println(collect);

        String stem1 = collectService.findstem(stem);

        if (stem1==null) {
            collectService.InsertAll(collect);
            return new Result("400", "收藏成功！");
        } else {

            return new Result("700", "已收藏！");
        }
    }



}
